﻿using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.Contract;
using OpenAuth.App.Contract.Request;
using OpenAuth.App.Interface;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OpenAuth.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "通用合同_CurryObjs")]
    public class ContractsController : ControllerBase
    {
        
        private readonly CurrencyApp _app;
        public ContractsController(IAuth auth, CurrencyApp app)
        {
            _app = app;
        }

        /// <summary>
        /// 添加合同
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response AddCurrency(Currency request)
        {

            var result = new Response();
            try
            {
                _app.Add(request);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<TableData> ShowCurrency([FromQuery] CurrencyDto  currency)
        {
                return await _app.Load(currency);
        }
        [HttpDelete]
        public Response DeleteCurrency([FromBody] string[] ids)
        {
            var result = new Response();
            try
            {
                _app.Delete(ids);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        [HttpPut]
        public Response UpdCurry(CurrencyAddDto currencyDto)
        {
            var result = new Response();
            try
            {
                _app.Upt(currencyDto);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
    }
}
